-- lion
-- created by cheny3
-- 召唤兽：雄狮傀儡

return {
    fetchInitData = function(classId)
        local dungeonId = ME.user.dbase:query("current_dungeon");
        return FormulaM.invoke("CALC_SPRING_LION_INIT_ATTRIB", dungeonId);
    end,

    doSummon = function(classId, para)
        if ActivityDungeonM.isInActivityBossLayer() then
            -- 雄狮BOSS层固定位置
            para["pos"] = 30;
        end
        return SummonM.apply(classId, para);
    end,

    canReviveCallSummon = function(classId)
        local dungeonId = ME.user.dbase:query("current_dungeon");
        local dbase = SummonM.query(classId, "dbase") or {};
        local args = dbase["enter_call_args"] or {};
        if table.indexOf(args["dungeon_id"] or {}, dungeonId) < 0 then
            -- 不是指定迷宫
            return false;
        end

        local summonBuilding = ME.user.dbase:query("summon_building") or {};
        if tonumber(summonBuilding[classId]) <= 0 then
            -- 没召唤过
            return false;
        end

        local summonList = SummonM.findSummonsByClassId(classId);
        if #summonList > 0 then
            -- 场上有没有死亡的
            return false;
        end

        return true;
    end,

    -- 玩家复活，尝试恢复宠物
    reviveCureSummon = function(classId)
        local summonList = SummonM.findSummonsByClassId(classId);
        if #summonList <= 0 then
            -- 场上没有存活的
            return false;
        end

        -- 恢复一只就好，满血
        local grid = summonList[1];
        local summon = grid.summon;
        if summon then
            local maxHp = summon:queryAttrib("max_hp");
            local curHp = summon:queryAttrib("hp");
            -- 不能超过上限
            local value = math.max(0, maxHp - curHp);
            if value > 0 then
                summon:addAttrib("hp", value);
                EventMgr.fire(event.SUMMON_RECOVER, grid:getPos());
            end
        end

        return true;
    end,
};
